// Foundation for Sites by ZURB
// foundation.zurb.com
// Licensed under MIT Open Source

////
/// @group functions
////

/// 返回指定位置的反方向
///
/// @param {Keyword} $dir - 使用 "top", "right", "bottom" 和 "left" 的方向
/// @return {Keyword} 指定方向的反方向
@function direction-opposite(
  $dir
) {
  $dirs: (top, right, bottom, left);
  $place: index($dirs, $dir);

  @if $place == null {
    @error 'direction-opposite: Invalid $dir parameter, expected a value from "#{$dirs}", found "#{$dir}".';
    @return null;
  }

  // 计算循环中相反的位置，从1开始
  $length: length($dirs);
  $demi: $length / 2;
  $opposite-place: (($place + $demi - 1) % $length) + 1;

  @return nth($dirs, $opposite-place);
}

